package cn.zbzcode.hrm.web.controller;

import cn.zbzcode.hrm.utils.AjaxResult;
import cn.zbzcode.hrm.utils.RedisUtils;
import org.springframework.web.bind.annotation.*;

//操作Redis
@RestController
public class RedisController {

    //@RequestParam("key"):从请求参数中获取名字为key的数据
    @RequestMapping(value = "/redis/set",method = RequestMethod.POST)
    public AjaxResult set(@RequestParam("key") String key , @RequestParam("value")String value){
        RedisUtils.INSTANCE.set(key ,value);
        return AjaxResult.me();
    }

    //@PathVariable("key") :从 url中获取参数
    @RequestMapping(value = "/redis/get/{key}",method = RequestMethod.GET)
    public AjaxResult get(@PathVariable("key") String key){
        String result = RedisUtils.INSTANCE.get(key);
        return AjaxResult.me().setResultObj(result);
    }


    @RequestMapping(value = "/redis/setex",method = RequestMethod.POST)
    public AjaxResult setex(@RequestParam("key") String key,
                            @RequestParam("seconds") int seconds ,
                            @RequestParam("value")String value){
        RedisUtils.INSTANCE.setex(key ,seconds,value);
        return AjaxResult.me();
    }
}